package com.nrgedge.magnolia.module.ace;

import info.magnolia.cms.core.Content;
import info.magnolia.cms.gui.dialog.ControlsManager;
import info.magnolia.cms.security.AccessDeniedException;
import info.magnolia.cms.util.ContentUtil;
import info.magnolia.module.ModuleLifecycle;
import info.magnolia.module.ModuleLifecycleContext;

import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;

public class AceEditorModule implements ModuleLifecycle {

	private boolean enabled = false;
	
	private String theme;
	
	@SuppressWarnings("deprecation")
	public void start(ModuleLifecycleContext moduleLifecycleContext) {
		
		try {
			
			Content content = ContentUtil.getContent("config", "/modules/adminInterface/controls/editCode");
			
			if (enabled) {
				content.setNodeData("class", "com.nrgedge.magnolia.module.ace.DialogEditCodeAce");
			} else {
				content.setNodeData("class", "info.magnolia.cms.gui.dialog.DialogEditCode");
			}
			
			ControlsManager.getInstance().reload();
			
		} catch (AccessDeniedException e) {
			e.printStackTrace();
		} catch (PathNotFoundException e) {
			e.printStackTrace();
		} catch (RepositoryException e) {
			e.printStackTrace();
		}
		
	}

	public void stop(ModuleLifecycleContext moduleLifecycleContext) {

	}

	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public String getTheme() {
		return theme;
	}

	public void setTheme(String theme) {
		this.theme = theme;
	}
	
	

}
